package com.chu.service.impl;

import com.chu.entity.Menu;
import com.chu.mapper.MenuMapper;
import com.chu.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuMapper menuMapper;
    //查询全部的权限
    @Override
    public List<Menu> findAllMenus() {
        List<Menu> menus = menuMapper.findAllMenus();
        ArrayList firstList = new ArrayList(); //对菜单列表分级 创建集合保存一级菜单

        for (Menu menu : menus) {

            if(menu.getUpmenuid()==0){//一级菜单

                ArrayList secondList = new ArrayList();//创建集合保存二级菜单
                for (Menu secondMenu : menus) {
                    if(menu.getMenuid()==secondMenu.getUpmenuid()){ //如果菜单的父id等于一级菜单的id 那么就是二级菜单
                        secondList.add(secondMenu); //保存二级菜单
                    }
                }
                menu.setMenuList(secondList); //将二级菜单保存到一级菜单当中
                firstList.add(menu);//将一级菜单添加到集合当中
            }
        }
        return firstList;
    }
    //根据角色id查询权限信息
    @Override
    public List<Menu> findMenusByRoleId(int roleId) {
        return null;
    }

    @Override
    public int deleteByPrimaryKey(Integer menuid) {
        return 0;
    }

    @Override
    public int insert(Menu record) {
        return 0;
    }

    @Override
    public int insertSelective(Menu record) {
        return 0;
    }

    @Override
    public Menu selectByPrimaryKey(Integer menuid) {
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(Menu record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(Menu record) {
        return 0;
    }
}
